package com.example.demo.Mapper;

import com.example.demo.entity.CardInfo;
import com.example.demo.entity.UserInfo;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

@Repository
@Mapper
public interface CardMapper {
    @Select("SELECT *,'credit_card' AS card_type \n" +
            "FROM finance.card a \n" +
            "WHERE a.card_id IN(SELECT b.card_id FROM finance.credit_card b)\n" +
            "UNION\n" +
            "SELECT *,'saving_card' AS card_type \n" +
            "FROM finance.card a \n" +
            "WHERE a.card_id IN(SELECT b.card_id FROM finance.saving_card b)\n" +
            "ORDER BY card_id")
    List<CardInfo> getCardsInfo();


    @Insert("insert into credit_card(card_id,due,limit_money) " +
            "values(#{card_id},#{0.0},#{5000.0})")
    public int addCreditCardInfo(int card_id);

    @Insert("insert into saving_card(card_id) " +
            "values(#{card_id})")
    public  int addSavingCardInfo(int card_id);

    @Insert("insert into finance.card(card_id,balance,bank_id) " +
            "values(#{card_id},#{balance},#{bank_id})")
    public int addCardInfo(int card_id,int client_id,double balance,int bank_id,String card_type,String time);

    @Insert("insert into finance.apply(card_id,client_id,time) " +
            "values(#{card_id},#{client_id},#{time})")
    public int addApply(int card_id,int client_id,String time);

    @Update("update card " +
            "set balance=#{balance},bank_id=#{bank_id} where card_id=#{card_id}")
    public int updateCardInfo(int card_id,double balance,int bank_id);

    @Update("update credit_card " +
            "set due=#{0.0},limit_money=#{5000.0} where card_id=#{card_id}")
    public int updateCreditCardInfo(int card_id);

  /*  @Delete("DELECT * FROM finance.card WHERE card_id = #{card_id}")
    public String delectcard(String card_id );
*/
}
